package cn.bone.vertx.demo02;

import io.vertx.core.AbstractVerticle;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;

/**
 * Created by superbone on 2017/2/9.
 */
public class HttpServer extends AbstractVerticle{

    @Override
    public void start() throws Exception {
        Router router = Router.router(vertx);
        router.route().handler(BodyHandler.create());
        router.get("/hello").handler(event -> {
            event.response().putHeader("content-type","text/html;charset=UTF-8")
                 .end("hello 你好啊vert.x");
        });
        router.get("/").handler(event -> {
            event.response().putHeader("content-type","text/html;charset=UTF-8")
                    .end("首页");
        });


        vertx.createHttpServer().requestHandler(request -> {
            router.accept(request);
        }).listen(1000);
    }

    public static void main(String[] args){
        Runner.run(HttpServer.class);
    }
}
